package login

import (
	"context"
	"net/http"
	"ruoyi_zero/utils"

	"github.com/zeromicro/go-zero/core/logx"
	"ruoyi_zero/domain/system"
	"ruoyi_zero/internal/svc"
	"ruoyi_zero/internal/types"
)

type LoginRoutersLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginRoutersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginRoutersLogic {
	return &LoginRoutersLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginRoutersLogic) LoginRouters() (resp *types.AjaxResult, err error) {
	// todo: add your logic here and delete this line
	userId := "1" //l.ctx.Value("userId")
	var user system.SysUser
	err = l.svcCtx.DB.Where("user_id = ?", userId).First(&user).Error

	resp = new(types.AjaxResult)

	menu := system.SelectMenuTreeByUserId(utils.GetInterfaceToInt(userId))
	var data = system.BuildMenus(menu)
	resp.Msg = "操作成功"
	resp.Code = http.StatusOK
	resp.Data = data
	return
}
